//transmit support for std::vector
//$Id: transmit_vector.h 522 2010-07-19 18:13:22Z Oleg.Bulychov $
#pragma once

#include <vector>
#include "src/heo/include/transmit.h"
//__________________________________________________________________________________
//__________________________________________________________________________________
template<class X, class A, class V>
struct transmit_handler<std::vector<X, A>, V>
{
    static void visit(std::vector<X, A>& vec, V& v)
    {
        visit(vec, v, meta::int2type<V::transmit_tag>());
    }

    static void visit(std::vector<X, A>& vec, V& bcast, meta::int2type<BCAST_TAG>)
    {
        if (bcast.is_Root())
        {
            visit(vec, bcast, meta::int2type<SEND_TAG>());
        }
        else
        {
            visit(vec, bcast, meta::int2type<RECV_TAG>());
        }
    }

    static void visit(std::vector<X, A>& vec, V& send, meta::int2type<SEND_TAG>)
    {
        size_t dim = vec.size();
        ////std::cout << "send v::size==" << dim << std::endl;
        send << dim;
        if (dim > 0)
            send.visit_Array(&vec[0], dim, "", 0);
    }

    static void visit(std::vector<X, A>& vec, V& recv, meta::int2type<RECV_TAG>)
    {
        size_t dim = 0;
        recv >> dim;
        ////std::cout << "recv v::size==" << dim << std::endl;
        ////if (dim > 1000)
        ////    __debugbreak();
        vec.resize(dim);
        if (dim > 0)
            recv.visit_Array(&vec[0], dim, "", 0);
    }
};
//__________________________________________________________________________________
//__________________________________________________________________________________

//EOF!
